<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/16 0016
 * Time: 下午 11:22
 */

namespace app\dlc\controller;
use app\common\model\Article;
use think\Db;

class ArticleController extends CommonController
{
    public function index()
    {

        $this->headBotton('','enable','批量通过','/dlc/'.$this->className.'/enableALl',2,'确定通过',true);

        $this->headBotton('','delete','批量删除','/dlc/'.$this->className.'/deleteALl',2,'确定删除',true);

        $this->headBotton('','add','添加','/dlc/'.$this->className.'/_edit');
        $this->headSearch('','title','标题','1');
        $this->headSearch('','url|1','url',1);
        $this->headSearch('','case_id','方案网站',2,Db::name('cases')->column('id,name'));
        $this->headSearch('','case_item_id','具体方案',2,Db::name('case_item')->column('id,name'));
        $this->headSearch('','status','状态',2,Article::$statusList);
        $this->listBotton('','edit','编辑','/dlc/'.$this->className.'/_edit');
        $this->listBotton('','enable','通过','/dlc/'.$this->className.'/disable','','确定通过？','','',['status','=','1']);
        $this->listBotton('','del','删除','/Dlc/'.$this->className.'/_del','1','确定删除？');
        $this->loading('index');
        $this->search('title',1);
        $map = $this->map;

        self::$page = self::$p . ',' . 50;
        $data = model($this->className)->where($map)->order('id desc')->page(self::$page)->select();
        foreach ($data as $key => $value) {
            $data[$key]['description'] = mb_substr($value['description'],0,20);
            $data[$key]['title'] = $this->listInput('',$value['id'],'title',$value['title']);
        }
        $count = Db::name($this->className)->where($map)->count();
        $this->getPage($count, self::$psize, 'App-loader', $this->title, 'App-search');
        $this->assign('data',$data);
        $list = ['id'=>'ID',
            'title'=>'标题',
            'keywords'=>'关键词',
            'description'=>'描述',
//            'content'=>'内容',
            'statusText'=>'状态',
            'ctime'=>'创建时间',
            'sys'=>'操作'];
        $this->assign('list',$list);
        echo $this->fetch('common/index');
    }

    public function enableALl(){
        $ids = input('ids');
        Db::name('article')->where(['id' => ['in', $ids],'status'=>1])->update(['status'=>2]);
        admin_return(1,'成功');


    }

    public function deleteALl(){
        $ids = input('ids');
        Db::name('article')->where(['id' => ['in', $ids],'status'=>1])->delete();
        admin_return(1,'成功');
    }

    public function test(){
        $list = Db::name('rep_r')->select();
        foreach ($list as $item) {
            Db::name('article')->where(['url' => $item['url']])->update(['status' => 3]);
            echo '----<br>';
        }

    }


}